#ifndef DEVICEINFOWINDOW_H
#define DEVICEINFOWINDOW_H

#include <QWidget>
#include <QTimer>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QListWidgetItem>
#include <QJsonObject>
#include <QJsonArray>
#include "baifa_cloud_client.h"

QT_BEGIN_NAMESPACE
namespace Ui { class DeviceInfoWindow; }
QT_END_NAMESPACE

class DeviceInfoWindow : public QWidget
{
    Q_OBJECT

public:
    DeviceInfoWindow(QWidget *parent = nullptr);
    ~DeviceInfoWindow();

private slots:
    void onRefreshClicked();
    void onCloseClicked();
    void onDeviceSelectionChanged();
    
    // 巴法云客户端响应槽函数
    void onDeviceListReceived(const QJsonArray &devices);
    void onDeviceDataReceived(const QString &topic, const QJsonObject &data);
    void onErrorOccurred(const QString &errorMsg);
    
    // 定时器槽函数
    void onRefreshTimer();

private:
    Ui::DeviceInfoWindow *ui;
    BaifaCloudClient *m_baifaClient;
    QTimer *m_refreshTimer;
    QString m_currentTopic;
    
    // UI相关方法
    void setupUI();
    void setupConnections();
    void updateDeviceList(const QJsonArray &devices);
    void updateDeviceData(const QJsonObject &data);
    void clearDeviceData();
    void updateConnectionStatus(bool connected);
};

#endif // DEVICEINFOWINDOW_H